package mx.com.crowdgine.camera;

import java.awt.Component;

import javax.media.opengl.GL2;

import mx.com.crowdgine.entity.Entity;
import mx.com.crowdgine.util.math.Vector3f;

public class GeneralCamera implements Camera {
	//Position of the camera
	protected Vector3f position = null;
	//Rotation around Y axis of the camera
	protected float yaw = 0.0f;
	//Rotation around X axis of the camera
	protected float pitch = 0.0f;
	protected boolean isAttached = false;
	protected Entity entity;

	@Override
	public void init(Component component) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void interact(Object renderingImplementation) {
		if(renderingImplementation instanceof GL2) {
    		this.interact((GL2)renderingImplementation);
    	} else {
    		throw new UnsupportedOperationException("Rendering implementation not supported yet: " + renderingImplementation);
    	}
	}
	
	public void interact(GL2 gl)
    {
        //roatate the pitch around the X axis
        gl.glRotatef(pitch, 1.0f, 0.0f, 0.0f);
        //roatate the yaw around the Y axis
        gl.glRotatef(yaw, 0.0f, 1.0f, 0.0f);
        //translate to the position vector's location
        gl.glTranslatef(-position.getX(), position.getY(), -position.getZ());
    }
	
	public void attachToEntity(Entity entity) {
		this.entity = entity;
		/*Vector3f entPos = entity.getPosition();
		this.position = new Vector3f(entPos.getX() + position.getX(),
				entPos.getY() + position.getY(), entPos.getZ()
						+ position.getZ());
		*/
		isAttached = true;
	}

	public void deattachFromEntity() {
		// this.entitiy = null;
		isAttached = false;
	}

	public boolean isAttached() {
		return isAttached;
	}

	
	public Vector3f getPosition() {
		return position;
	}

	public void setPosition(Vector3f position) {
		this.position = position;
	}
	
	public void setYaw(float yaw){
		this.yaw = yaw;
	}
	
	public void setPitch(float pitch){
		this.pitch = pitch;
	}

}
